<?php

class Controller_Base extends FLEA_Controller_Action
{
	var	$viewdata;
	
	function	Controller_Base()
	{
	}
	
	function	show()
	{
		$this->_executeView("display.php",$this->viewdata);	
	}
	
	function	showResultView()
	{
		$this->_executeView("result.php",$this->viewdata);	
	}
	
	function	showResult($result)
	{
		print '<data><result>';
		print $result;
		print '</result></data>';
	}
	function	checkLogin()
	{
		session_start();
		$userID	=	$UserID;
		if($userID == "")
		{
			/**
			 * 没有登陆
			 */
			return 0;
		}

		$_modelUser		=&	FLEA::getSingleton("Model_User");
		$user 			=	$_modelUser->findUser($userID);
		$this->viewdata['user']	=	$user;
		
		if($this->viewdata['user']['IPManager'] == 1)
		{
			return 5;
		}
		else if($this->viewdata['user']['client']['ClientID'] != "")
		{
			return 1;
		}
		else if($this->viewdata['user']['inventor']['InventorID'] !="")
		{
			$this->viewdata['user']['client']['ClientID']	=	$this->viewdata['user']['inventor']['ClientID'];
			return 2;
		}
		else if($this->viewdata['user']['firm']['FirmID'] != "")
		{
			return 3;
		}
		else if($this->viewdata['user']['practitioner']['PractitionerID'] != "")
		{
			$this->viewdata['user']['firm']['FirmID']	=	$this->viewdata['user']['practitioner']['FirmID'];
			return 4;
		}
	}
	
	function  getInt($u)
	{
		return $u==''?0:$u;
	}
	function purse($arr,$pa,$index)
	{
		if(is_numeric($pa))
		{
			$pa	=	"Data";
		}
		for($i=0; $i<$index; $i++)
		{
			$t	.=	"      ";
		}
		$t1	=	$t."      ";
		
		print $t."<".$pa.">\n";
		
		foreach($arr as $key=> $value)
		{
			if(is_array($value))
			{
				$this->purse($value,$key,$index+1);
			}
			else
			{
				print $t1."<".$key.">".htmlspecialchars($value)."</".$key.">\n";
			}
		}
		print $t."</".$pa.">\n";
	}
	
	function sendMail($SmtpEmailTo,$mailsubject,$mailBody,$mailHeader)
	{
		require_once("Extra/Mail.php");
		set_time_limit(100);
			
		$smtp = new smtp(SmtpServer,Smtpserverport,true,SmtpUser,SmtpPass);
		$smtp->debug = true;

		$re		= $smtp->sendmail($SmtpEmailTo,SmtpUserMail,$mailsubject,$mailBody,"","","",$mailHeader);
		return $re;
	}
}
?>